"""
==============================================================
#   author：教室工作室  (1036198123@qq.com) 原创
#   time：2020.11.17
#   filename：picgame.py
#   ver：V1.0
#   des：猜图游戏主程序
#   MIT License
#   Copyright (c) 2020 教室工作室 
#   Python 3.7 运行正常
==============================================================
"""
import tkinter as tk
from tkinter import StringVar
import tkinter.messagebox 
import tkinter.filedialog
from PIL import Image, ImageTk
import 图像识别example

class App(tk.Frame):

  def __init__(self, master=None):
    super().__init__(master, width=600, height=300)

    self.pack()
    global A,B,C,a,b,c
    a,b,c={},{},{}
    A,B,C=StringVar(),StringVar(),StringVar()
    path=""
    #输入框，标记，按键
    tk.Label(self,text = "目标路径:").grid(row = 0, column = 0)
    #输入框绑定变量path
    tk.Entry(self, textvariable = path).grid(row = 0, column = 1)
    tk.Button(self, text = "路径选择", command =self.selectPath).grid(row = 0, column = 2)
    self.Button1=tk.Button(self,textvariable=A, command=self.pressA).grid(row=2,column=1)
    self.Button2=tk.Button(self,textvariable=B, command=self.pressB).grid(row=2,column=2)
    self.Button3=tk.Button(self,textvariable=C, command=self.pressC).grid(row=2,column=3)
  def selectPath(self):
    global a,b,c
    #选择文件path_接收文件地址
    path_ = tkinter.filedialog.askopenfilename()
    #通过replace函数替换绝对文件地址中的/来使文件可被程序读取 
    #注意：\\转义后为\，所以\\\\转义后为\\
    path_=path_.replace("/","\\\\")
    self.pilImage = Image.open(path_)
    self.tkImage = ImageTk.PhotoImage(image=self.pilImage)
    self.label = tk.Label(self, image=self.tkImage)
    self.label.grid(row=1,column=1,columnspan=3)
    x=图像识别example.识别函数(path_,A,B,C)
    a=x[0]
    b=x[1]
    c=x[2]
    #print(a,b,c)
 
  def pressA(self):
      global a
      print(a)
      if a["score"]>b["score"]and a["score"]>c["score"]:
          tk.messagebox.showinfo('提示','你和AI猜的一样！')
      else:
          tk.messagebox.showinfo('提示','你和AI猜的不一样')
  def pressB(self):
      global b
      if b["score"]>a["score"]and b["score"]>c["score"]:
          tk.messagebox.showinfo('提示','你和AI猜的一样！')
      else:
          tk.messagebox.showinfo('提示','你和AI猜的不一样')
  def pressC(self):
      global c
      if c["score"]>b["score"]and c["score"]>a["score"]:
          tk.messagebox.showinfo('提示','你和AI猜的一样！')
      else:
          tk.messagebox.showinfo('提示','你和AI猜的不一样')

if __name__ == '__main__':
    root = tk.Tk()
    root.title('AI猜图游戏')
    app = App(root)
     
    root.mainloop()